package org.example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.example.dto.OrderDTO;
import org.example.service.OrdersService;
import java.util.List;

@RestController
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    // 创建订单
    @PostMapping("/createOrders")
    public int createOrders(@RequestParam("userId") String userId,
            @RequestParam("businessId") Integer businessId,
            @RequestParam("daId") Integer daId,
            @RequestParam("orderTotal") Double orderTotal) {
        return ordersService.createOrders(userId, businessId, daId, orderTotal);
    }

    // 根据订单ID获取订单信息
    @GetMapping("/getOrdersById")
    public OrderDTO getOrdersById(@RequestParam("orderId") Integer orderId) {
        return ordersService.getOrdersById(orderId);
    }

    // 根据用户ID获取所有订单信息
    @GetMapping("/listOrdersByUserId")
    public List<OrderDTO> listOrdersByUserId(@RequestParam("userId") String userId) {
        return ordersService.listOrdersByUserId(userId);
    }
}